package com.cloud.code.牛客网;

import java.util.Scanner;

public class Test56 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String line = scanner.nextLine();
            String[] s = line.split(" ");


            doOprate(s);


        }
    }

    private static void doOprate(String[] strings) {

        int sum = 0;
        int copy = 0;

        boolean sele = false;
        for (int i = 0; i < strings.length; i++) {

            String string = strings[i];
            switch (string) {
                case "1":
                    if (sele) {
                        sele = false;
                        sum = 1;
                    } else {
                        sum = sum + 1;
                    }
                    break;
                case "2":
                    if (!sele) {
                        continue;
                    } else {
                        copy = sum;
                    }
                    break;
                case "3":
                    if (!sele) {
                        continue;
                    } else {
                        copy = sum;
                        sum = 0;
                    }
                    break;
                case "4":
                    if (sele) {
                        sele = false;
                        sum = copy;
                    } else {
                        sum = sum + copy;
                    }
                    break;
                case "5":
                    sele = true;
                    break;
            }
        }

        System.out.println(sum);

    }
}
